export function getIdInfo(resolve, reject) {
    wx.chooseImage({
        count: 9, // 最多可以选择的图片张数，默认9
        sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
        sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
        success: function(res){
            // success
            console.log(res)
            wx.getFileSystemManager().readFile({
                filePath: res.tempFilePaths[0], //图片压缩后路径
                encoding: "base64",
                success: function (info) {
                    let base64Data = "data:image/jpg;base64," + info.data; //data:image/图片类型;base64, 图片头, 如果图片是png格式：data:image/png;base64, 如果图片是jpg格式：data:image/jpg;base64,
                    console.log(base64Data);//打印图片base64码
                    wx.request({
                        url: "https://ocridcard.market.alicloudapi.com/idCardAuto",
                        method: "POST",
                        data: {
                            //"image":"http://img3.fegine.com/image/bank.jpg" //传递公网url方式
                            "image": base64Data //将图片转换成base64上传方式
                        },
                        header: {
                            "content-type": "application/x-www-form-urlencoded",
                            "Authorization": "APPCODE 7149afd9fe01415c9942b6d16d8b5090" //开通服务后 买家中心-查看AppCode
                        },
                        success: function (res) {
                            let resCode = res.statusCode;
                            let message = res.header['X-Ca-Error-Message'];

                            if (resCode == 200) {
                                console.log("正常请求计费(其他均不计费)");
                                console.log(res.data, 'res');
                                if (res.data.code === '1') {
                                    console.log('跑出结果了')
                                    resolve(res.data.result)
                                    return
                                } else if (res.data.code === '2') {
                                    reject('请上传身份证正面')
                                    return
                                } else {
                                    reject(res.data.msg)
                                    return
                                }
                            } else if (resCode == 400 && message == "Invalid Param Location") {
                                reject("参数错误");
                                return

                            } else if (resCode == 400 && message == "Invalid AppCode") {
                                reject("AppCode错误");
                                return
                            } else if (resCode == 400 && message == "Invalid Url") {
                                reject("请求的 Method、Path 或者环境错误");
                                return
                            } else if (resCode == 403 && message == "Unauthorized") {
                                reject("服务未被授权（或URL和Path不正确）");
                                return
                            } else if (resCode == 403 && message == "Quota Exhausted") {
                                reject("套餐包次数用完");
                                return
                            } else if (resCode == 500) {
                                reject("API网关错误");
                                return
                            } else {
                                console.log("参数名错误 或 其他错误");
                                console.log(resCode);
                                reject(message);
                                return
                            }
                        },
                        fail: function (res) {
                            reject('URL错误')
                            return
                        },
                    });
                }
            })
        },
        fail: function() {
            // fail
            reject()
            return
        },
        complete: function() {
            // complete
            reject()
            return
        }
    })
}
